package com.hrzyit.whistle.cases.widgets

import android.content.Context
import com.hrzyit.base.ext.onClick
import com.hrzyit.whistle.cases.R
import com.hrzyit.whistle.cases.data.bean.AudioInfo
import com.hrzyit.whistle.cases.presenter.RecordAudioPresenter
import com.lxj.xpopup.animator.PopupAnimator
import com.lxj.xpopup.core.CenterPopupView
import kotlinx.android.synthetic.main.popup_case_accept.view.*
import org.jetbrains.anko.toast

/**
 * 弹出窗口：录音保存确认界面
 * @author YangWei
 * @date 2019/4/21
 */
class SaveAudioConfirmPopup (context: Context): CenterPopupView(context) {

    lateinit var audioInfo: AudioInfo

    lateinit var recordAudioPresenter:RecordAudioPresenter

    // 返回自定义弹窗的布局
    override fun getImplLayoutId(): Int {
        return R.layout.popup_audio_confirm
    }

    // 执行初始化操作，比如：findView，设置点击，或者任何你弹窗内的业务逻辑
    override fun onCreate() {
        super.onCreate()
        mConfirmBtn.onClick{
            context.toast("保存录音")
            audioInfo.let {
                recordAudioPresenter.uploadRecordAudio(audioInfo.voiceFilePath!!)
            }
        }
        mCancelBtn.onClick{
            context.toast("重新录制")
            // 需要初始化
            dismiss() // 关闭弹窗
        }
    }

    // 设置最大宽度，看需要而定
    override fun getMaxWidth(): Int {
        return super.getMaxWidth()
    }

    // 设置最大高度，看需要而定
    override fun getMaxHeight(): Int {
        return super.getMaxHeight()
    }

    // 设置自定义动画器，看需要而定
    override fun getPopupAnimator(): PopupAnimator {
        return super.getPopupAnimator()
    }
}